package com.controller;


import com.controller.dao.AccountDao;
import com.controller.model.Account;

import javax.servlet.http.HttpServletRequest;
public class LoginController {

    private  final AccountDao accountDao;

    public LoginController(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public String login(HttpServletRequest httpServletRequest) {
        final String userName = httpServletRequest.getParameter("username");
        final String password = httpServletRequest.getParameter("password");
        try{
            Account account = accountDao.findAccount(userName, password);
            if(account==null){
                return "/login";
            }else{
                return "/index";
            }
        }catch (Exception e){
            return "505";
        }

    }
}
